package com.example.broadcastnotification;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.util.Log;

import static android.content.ContentValues.TAG;

public class MyReceiver extends BroadcastReceiver {
public static final String ACTION = "com.example.broadcastnotification.intent.action.MyReceiver";
    @Override
    public void onReceive(Context context, Intent intent) {
        System.out.println("!!!!!");
        sendNotification(context);
    }

        private void  sendNotification(Context context){
            NotificationManager notifyMgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            NotificationCompat.Builder builder1 = new NotificationCompat.Builder(context);

            builder1.setSmallIcon(R.mipmap.ic_launcher);
            builder1.setContentTitle("提示");
            builder1.setContentText("enjoy summer days");
            builder1.setSubText("notification");
//            builder1.setTicker("this is a notification");
            builder1.setAutoCancel(true);

            Intent mIntent = new Intent(context,MainActivity.class);
            PendingIntent pi = PendingIntent.getActivity(context,0, mIntent,0);
            builder1.setContentIntent(pi);
            Notification notify1=builder1.build();

            notifyMgr.notify(1,notify1);
        }

}
